package com.bytedance.ttstat;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import com.bytedance.article.common.a.h;
import com.bytedance.common.utility.Logger;
import com.ss.android.article.lite.ArticleApplication;

import java.util.Map;
import java.util.WeakHashMap;

public final class a {
    public static final class a$a {
        private final ArticleApplication a;

        public a$a(ArticleApplication arg1) {
            this.a = arg1;
        }

        public final int a() {
            int v0_1;
            try {
                v0_1 = android.support.design.a.d(this.a.getApplicationContext(), "SS_VERSION_CODE");
            } catch (Exception v0) {
                try {
                    v0_1 = this.a.getPackageManager().getPackageInfo(this.a.getPackageName(), PackageManager.GET_ACTIVITIES).versionCode;
                } catch (PackageManager.NameNotFoundException v0_2) {
                    v0_2.printStackTrace();
                    v0_1 = -1;
                }
            }

            return v0_1;
        }
    }

    private static final Map a = new WeakHashMap();
    private static final Map b = new WeakHashMap();
    private static final Map c = new WeakHashMap();
    private static final Map d = new WeakHashMap();

    private static f a(Context arg2) {
        f v0_1;
        v0_1 = (f) a.get(arg2);
        if (v0_1 == null) {
            v0_1 = new f();
            a.put(arg2, v0_1);
        }

        return v0_1;
    }

    public static void a() {
        h.c(true);
    }

    public static void a(Activity arg10) {
        f v0 = a(((Context) arg10));
        String v1 = arg10.getClass().getSimpleName();
        v0.showSplashTs2 = System.currentTimeMillis();
        long v2 = v0.showSplashTs2 - v0.showSplashTs1;
        Logger.d(v1, "Start activity to show Splash Pic Time = " + v2);
        if (v2 > 0 && v2 < 15000) {
            android.support.design.a.a("startToAdShowTime", v2);
        }

        v2 = v0.showSplashTs2 - v0.d;
        if (v2 > 0 && v2 < 15000) {
            android.support.design.a.a("resumeToAdShow", v2);
        }

        long v0_1 = v0.showSplashTs2 - h.l();
        if (v0_1 > 0 && v0_1 < 15000) {
            if (h.p()) {
                android.support.design.a.a("firstApplicationToAdShow", v0_1);
            } else {
                android.support.design.a.a("applicationToAdShow", v0_1);
            }
        }
    }

    public static void a(Application arg4) {
        c v0 = h(arg4);
        long v2 = System.currentTimeMillis();
        h.d(v2);
        v0.g = v2;
    }

    @TargetApi(value = 14)
    public static void a(Application application, a$a arg2) {
        application.registerActivityLifecycleCallbacks(new com.bytedance.ttstat.b(arg2, application));
    }

    public static void a(Application arg6, boolean arg7) {
        c v0 = h(arg6);
        v0.pluginInitTs2 = System.currentTimeMillis();
        if ((arg7) && (com.bytedance.ttstat.c.a(v0.pluginInitTs2 - v0.pluginInitTs1))) {
            android.support.design.a.a("pluginInitTime", v0.pluginInitTs2 - v0.pluginInitTs1);
        }
    }

    public static void a(Context arg13, boolean arg14) {
        long v4;
        long v10 = 0;
        long v0 = System.currentTimeMillis();
        long v2 = c(arg13).onCreateTs1;
        if ((android.support.design.a.i) && !android.support.design.a.j && (h.f()) && !android.support.design.a.p) {
            if (android.support.design.a.l) {
                v4 = android.support.design.a.n;
                if ((android.support.design.a.k) && v4 > v10 && v0 > v4 && v0 - v4 < 10000) {
                    android.support.design.a.a("hotApplicationToFeedShown", v0 - v4);
                    if (v2 > v10) {
                        android.support.design.a.a("mainOnCreateToFeedShow_hot", v0 - v2);
                    }
                    if (!arg14) {
//                        goto label_41;
                    } else {
                        Log.i("DateTime", "hotApplicationToFeedShown " + (v0 - v4) + "ms");
                    }
                }
            } else {
                v4 = android.support.design.a.m;
                if (v4 <= v10) {
//                    goto label_41;
                } else if (v0 <= v4) {
//                    goto label_41;
                } else if (v0 - v4 >= 20000) {
//                    goto label_41;
                } else if (h.p()) {
                    android.support.design.a.a("firstApplicationToFeedShown", v0 - v4);
                    if (v2 > v10) {
                        android.support.design.a.a("mainOnCreateToFeedShow_first", v0 - v2);
                    }

                    if (!arg14) {
//                        goto label_41;
                    } else {
                        Log.i("DateTime", "firstApplicationToFeedShown " + (v0 - v4) + "ms");
//                        goto label_41;
                    }
                } else {
                    if (android.support.design.a.o) {
                        android.support.design.a.a("applicationDelayToFeedShown", v0 - v4);
                    } else {
                        android.support.design.a.a("applicationToFeedShown", v0 - v4);
                    }

                    if (v2 <= v10) {
//                    goto label_41;
                    } else {
                        android.support.design.a.a("mainOnCreateToFeedShow_cold", v0 - v2);
                    }
                }
            }
        }
        android.support.design.a.i = false;
        android.support.design.a.j = false;
        android.support.design.a.l = false;
        android.support.design.a.p = false;
        android.support.design.a.n = v10;
        android.support.design.a.m = v10;
        android.support.design.a.o = false;
    }

    private static e b(Context arg2) {
        Object v0 = b.get(arg2);
        if (v0 == null) {
            e v0_1 = new e();
            b.put(arg2, v0_1);
        }

        return ((e) v0);
    }

    public static void b() {
        h.f(System.currentTimeMillis());
    }

    public static void b(Activity arg6) {
        f v0 = a(((Context) arg6));
        h.c(System.currentTimeMillis());
        if (h.q() <= 0) {
            h.b(true);
        } else if (System.currentTimeMillis() - h.q() < 200) {
            h.a(h.l());
        }

        v0.showSplashTs1 = System.currentTimeMillis();
        h.b(v0.showSplashTs1);
    }

    public static void b(Application arg4) {
        h(arg4).e = System.currentTimeMillis();
    }

    public static void b(Application arg6, boolean arg7) {
        c v0 = h(arg6);
        v0.pluginInitTs1 = System.currentTimeMillis();
        if ((arg7) && (com.bytedance.ttstat.c.a(v0.pluginInitTs1 - v0.c))) {
            android.support.design.a.a("beforePluginInitTime", v0.pluginInitTs1 - v0.c);
        }
    }

    private static com.bytedance.ttstat.d c(Context context) {
        com.bytedance.ttstat.d v0_1;
        v0_1 = (com.bytedance.ttstat.d) c.get(context);
        if (v0_1 == null) {
            v0_1 = new com.bytedance.ttstat.d();
            c.put(context, v0_1);
        }

        return v0_1;
    }

    public static void c() {
        h.e(true);
    }

    public static void c(Activity arg10) {
        long v8 = 15000;
        long v6 = 0;
        f v0 = a(((Context) arg10));
        String v1 = arg10.getClass().getSimpleName();
        v0.showSplashTs2 = System.currentTimeMillis();
        long v2 = v0.showSplashTs2 - v0.showSplashTs1;
        Logger.d(v1, "Start activity to show Splash Pic Time = " + v2);
        if (v2 > v6 && v2 < v8) {
            android.support.design.a.a("startToAdShowTime", v2);
        }

        v2 = v0.showSplashTs2 - v0.d;
        if (v2 > v6 && v2 < v8) {
            android.support.design.a.a("resumeToAdShow", v2);
        }

        long v0_1 = v0.showSplashTs2 - h.l();
        if (v0_1 > v6 && v0_1 < v8) {
            if (h.p()) {
                android.support.design.a.a("firstApplicationToAdShow", v0_1);
            } else {
                android.support.design.a.a("applicationToAdShow", v0_1);
            }
        }
    }

    public static void c(Application arg4) {
        h(arg4).f = System.currentTimeMillis();
    }

    public static void d() {
        h.a(true);
    }

    public static void d(Activity arg10) {
        long v8 = 15000;
        long v6 = 0;
        f v0 = a(((Context) arg10));
        String v1 = arg10.getClass().getSimpleName();
        v0.c = System.currentTimeMillis();
        long v2 = v0.c - v0.showSplashTs2;
        if (v2 > v6 && v2 < v8) {
            android.support.design.a.a("splashAdShowTime", v2);
        }

        v2 = v0.c - v0.showSplashTs1;
        if (v2 > v6 && v2 < v8) {
            android.support.design.a.a("splashCreateToStop", v2);
        }

        Logger.d(v1, "SplashActivity duration: " + (v0.c - v0.showSplashTs1));
    }

    public static void d(Application arg4) {
        h(arg4).a = System.currentTimeMillis();
    }

    public static void e() {
        h.d(true);
    }

    public static void e(Activity arg8) {
        long v6 = 0;
        f v0 = a(((Context) arg8));
        if (h.m() > v6) {
            android.support.design.a.a("appHotStartTime", System.currentTimeMillis() - h.m());
            h.c(v6);
        }

        v0.d = System.currentTimeMillis();
    }

    public static void e(Application arg6) {
        c v0 = h(arg6);
        long v2 = System.currentTimeMillis();
        h.e(v2);
        long v4 = v2 - v0.a;
        if (com.bytedance.ttstat.c.a(v4)) {
            android.support.design.a.a("articleApplicationTime", v4);
        }

        v0.h = v2;
    }

    public static void f(Activity arg4) {
        b(((Context) arg4)).a = System.currentTimeMillis();
    }

    public static void f(Application arg4) {
        h(arg4).c = System.currentTimeMillis();
    }

    public static void g(Activity arg4) {
        e v0 = b(((Context) arg4));
        v0.b = System.currentTimeMillis();
        long v0_1 = v0.b - v0.a;
        if (v0_1 > 0 && v0_1 < 15000) {
            android.support.design.a.a("hotStartToAdShowTime", v0_1);
        }

        h.c(true);
    }

    public static void g(Application arg6) {
        c v0 = h(arg6);
        long v2 = System.currentTimeMillis();
        if (com.bytedance.ttstat.c.a(v2 - v0.pluginInitTs2)) {
            android.support.design.a.a("afterPluginToEnd", v2 - v0.pluginInitTs2);
        }
    }

    static c h(Application arg2) {
        c v0_1;
        v0_1 = (com.bytedance.ttstat.c) d.get(arg2);
        if (v0_1 == null) {
            v0_1 = new c();
            d.put(arg2, v0_1);
        }

        return v0_1;
    }

    public static void h(Activity arg4) {
        e v0 = b(((Context) arg4));
        v0.c = System.currentTimeMillis();
        long v0_1 = v0.c - v0.b;
        if (v0_1 > 0 && v0_1 < 15000) {
            android.support.design.a.a("splashAdShowTime", v0_1);
        }
    }

    public static void i(Activity arg4) {
        a(((Context) arg4)).e = System.currentTimeMillis();
    }

    public static void j(Activity arg4) {
        String v0_1;
        f v0 = a(((Context) arg4));
        v0.f = System.currentTimeMillis();
        if (f.a(v0.f)) {
            long v2 = v0.f - v0.e;
            if (v2 > 0 && v2 < 15000) {
                if (h.g()) {
                    v0_1 = "splashOnCreate_hot";
                } else if (h.p()) {
                    v0_1 = "splashOnCreate_first";
                } else {
                    v0_1 = "splashOnCreate_cold";
                }

                android.support.design.a.a(v0_1, v2);
            }
        }
    }

    public static void k(Activity arg4) {
        a(((Context) arg4)).g = System.currentTimeMillis();
    }

    public static void l(Activity arg12) {
        String v0_1;
        long v10 = 15000;
        long v8 = 0;
        f v0 = a(((Context) arg12));
        long v2 = System.currentTimeMillis();
        if (f.a(v2)) {
            long v4 = v0.g - v0.f;
            v2 -= v0.g;
            if (v4 > v8 && v4 < v10) {
                if (h.g()) {
                    v0_1 = "splashOnCreateToOnResume_hot";
                } else if (h.p()) {
                    v0_1 = "splashOnCreateToOnResume_first";
                } else {
                    v0_1 = "splashOnCreateToOnResume_cold";
                }

                android.support.design.a.a(v0_1, v4);
            }

            if (v2 <= v8) {
                return;
            }

            if (v2 >= v10) {
                return;
            }

            if (h.g()) {
                v0_1 = "splashOnResume_hot";
            } else if (h.p()) {
                v0_1 = "splashOnResume_first";
            } else {
                v0_1 = "splashOnResume_cold";
            }
            android.support.design.a.a(v0_1, v2);
        }
    }

    public static void beforeOnCreate(Activity activity) {
        c((Context) activity).onCreateTs1 = System.currentTimeMillis();
    }

    public static void afterSuperOnCreate(Activity activity) {
        c((Context) activity).onCreateTs2 = System.currentTimeMillis();
    }

    public static void beforeSuperOnResume(Activity activity) {
        c((Context) activity).onResumeTs1 = System.currentTimeMillis();
    }

    public static void afterSuperOnResume(Activity arg12) {
        String v0_1;
        int v0 = 1;
        long v10 = 0;
        com.bytedance.ttstat.d v2 = c(((Context) arg12));
        long v4 = System.currentTimeMillis();
        if (android.support.design.a.l) {
            if (android.support.design.a.n > v10 && v4 - android.support.design.a.n < 10000) {
//                goto label_13;
            } else {
                v0 = 0;
            }
        } else {
            if (android.support.design.a.m > v10 && v4 - android.support.design.a.m < 20000) {
//                goto label_13;
            } else {
                v0 = 0;
            }
        }

        label_13:
        if (v0 != 0) {
            long v6 = v2.onCreateTs2 - v2.onCreateTs1;
            long v8 = v2.onResumeTs1 - v2.onCreateTs2;
            long v2_1 = v4 - v2.onResumeTs1;
            if (v6 > v10) {
                if (android.support.design.a.l) {
                    v0_1 = "mainOnCreate_hot";
                } else if (h.p()) {
                    v0_1 = "mainOnCreate_first";
                } else {
                    v0_1 = "mainOnCreate_cold";
                }

                android.support.design.a.a(v0_1, v6);
            }

            if (v8 > v10) {
                if (android.support.design.a.l) {
                    v0_1 = "mainOnCreateToOnResume_hot";
                } else if (h.p()) {
                    v0_1 = "mainOnCreateToOnResume_first";
                } else {
                    v0_1 = "mainOnCreateToOnResume_cold";
                }

                android.support.design.a.a(v0_1, v8);
            }

            if (v2_1 <= v10) {
                return;
            }

            if (android.support.design.a.l) {
                v0_1 = "mainOnResume_hot";
            } else if (h.p()) {
                v0_1 = "mainOnResume_first";
            } else {
                v0_1 = "mainOnResume_cold";
            }

            android.support.design.a.a(v0_1, v2_1);
        }
    }

    public static void q(Activity arg11) {
        long v2;
        long v8 = 0;
        c(((Context) arg11));
        if (h.o() > v8 && (h.n())) {
            android.support.design.a.a("clickAdToMainTime", System.currentTimeMillis() - h.o());
        }

        h.f(v8);
        h.e(false);
        long v0 = System.currentTimeMillis();
        android.support.design.a.i = h.k();
        android.support.design.a.j = h.j();
        android.support.design.a.k = h.d();
        android.support.design.a.l = h.g();
        android.support.design.a.m = h.h();
        android.support.design.a.n = h.i();
        android.support.design.a.o = h.b();
        android.support.design.a.p = h.c();
        if ((h.k()) && !h.j() && (h.f()) && !h.c()) {
            if (h.g()) {
                v2 = h.i();
                if ((h.d()) && (h.k()) && v2 > v8 && v0 > v2 && v0 - v2 < 5000) {
                    android.support.design.a.a("hotApplicationToMain", v0 - v2);
                }
            } else {
                v2 = h.h();
                if (v2 > v8 && v0 > v2 && v0 - v2 < 10000) {
                    if (h.p()) {
                        android.support.design.a.a("firstApplicationToMain", v0 - v2);
                    } else if (h.b()) {
                        android.support.design.a.a("applicationDelayToMain", v0 - v2);
                    } else {
                        android.support.design.a.a("applicationToMain", v0 - v2);
                    }
                }
            }
        }

        h.d(false);
        h.c(false);
        h.b(false);
        h.a(false);
        h.b(v8);
        h.a(v8);
        h.a();
        h.e();
    }
}

